package auerstreet.realbrainsports;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class RealBrainSports extends Activity {
	private Button button1;
	private Button button2;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		button1 = (Button) findViewById(R.id.button1);
		button2 = (Button) findViewById(R.id.button2);  
		
		show2Problems();
		
		button1.setOnClickListener(onClickListener);
		button2.setOnClickListener(onClickListener);
	}
	
	// Create an anonymous implementation of OnClickListener
	private OnClickListener onClickListener = new OnClickListener() {
	    public void onClick(View v) {
	    	show2Problems();
	    }
	};
	
	private void show2Problems() {
		showProblemOnButton(button1); 
		showProblemOnButton(button2);
	}

	private void showProblemOnButton(Button button) {
		int number1 = randomInt(10);
		int number2 = randomInt(10);
		String operator = randomOperator();
		button.setText(number1 + operator + number2);
	}

	private String randomOperator() { 
		String operators[] = { "+", "-", "*" };
		int operatorCode = randomInt(2);
		return operators[operatorCode];
	}

	/**
	 * @param max
	 * @return a random value between 0 and max (max inclusive)
	 */
	private int randomInt(int max) {
		return (int) (Math.random() * (max + 1));
	}
}